# -*- encoding: utf-8 -*-
#!/usr/bin/python2

from setuptools import setup
import os, sys
import subprocess
import glob

PLUGIN_PACKS = ["defaults", "extras"]
PACKAGE_DATA = {'etude' : ['data/*.png', 'data/*.svg', 'data/eq_presets.conf']}
LANGUAGES = ('hu', 'zh_CN', 'tr', 'fr', 'ca')
#LANGUAGES = ('zh_CN',)

if '--enable-visual' in sys.argv:
    PLUGIN_PACKS.append("visual")
    sys.argv.remove('--enable-visual')

# test if it's going to be a source distribution
if 'sdist' not in sys.argv:
    PACKAGE_DATA['etude'] += ['plugins/*.egg',]

    
def build_plugins():
    cdir = os.path.dirname(os.path.abspath(__file__))
    if os.path.exists("plugins"):
        os.chdir("plugins")
        for ppack in PLUGIN_PACKS:
            os.chdir(ppack)
            try:
                subprocess.call(["python", "setup.py", "bdist_egg", "-d", 
                    os.path.join(cdir, "etude", "plugins")])
            except subprocess.CalledProcessError:
                print("Error creating egg "+ppack)
                sys.exit(1)
            os.chdir('..')
    os.chdir(cdir)

def build_mo():
    if not os.path.exists("locale"):
        os.mkdir("locale/")
    for lang in LANGUAGES:
        pofile = "po/" + lang + ".po"
        mofile = "locale/"+ lang + "/etude.mo"
        if not os.path.exists("locale/" + lang + "/"):
            os.mkdir("locale/" + lang + "/")
        print "generating", mofile
        os.system("msgfmt %s -o %s" % (pofile, mofile))


if len(sys.argv) == 1 or ('--help' not in sys.argv and all(arg[0] != '-' for arg in sys.argv)):
	# FIXME hook these into "build", rather than test flags
	# current test is inaccurate anyway, e.g. 'setup.py --name build' builds rather than displays name
	build_plugins()
	build_mo()


setup(
        name="etude-music-player",
        version='0.1',
        url="http://code.google.com/p/etude-music-player/",
        description="pygtk client for xmms2",
        author="Szentandrási István",
        license="LGPL v3",
        classifiers=['Development Status :: 4 - Beta',
            'Environment :: X11 Applications',
            'Intended Audience :: End Users/Desktop',
            'License :: Lesser GNU General Public License (LGPL)',
            'Operating System :: Linux',
            'Programming Language :: Python',
            'Topic :: Multimedia :: Sound :: Players',
            ],
        packages=["etude", "etude.gui", "etude.client"],
        package_data= PACKAGE_DATA,
        #scripts=['etude.py'],
        data_files=[('share/applications', ['etude.desktop']),
            ('share/pixmaps', ['etude/data/etude.svg']),
            ('share/icons/hicolor/32x32/apps', ['etude/data/etude.png']),
            ('share/icons/hicolor/scalable/apps', glob.glob('etude/data/*.svg')),
            ('share/locale/zh_CN/LC_MESSAGES', ['locale/zh_CN/etude.mo']),
            ('share/locale/hu/LC_MESSAGES', ['locale/hu/etude.mo']),
            ],
        entry_points = {'gui_scripts' : 'etude = etude.main:main'}
        )
        
